<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no" />
    <link rel="stylesheet" type="text/css" href="../css/shangchengchaxun.css" />
    <title>商城查询</title>
</head>
<body>
    <div class="content">
        <div class="input">
            <div class="item">
                <div class="name">手机号</div>
                <div class="inp"><input type="tel" id="phone" placeholder="请输入手机号码"></div>
            </div>
        </div>
        <div class="input">
            <div class="item">
                <div class="inp"><input type="phone" id="verify" placeholder="请输入图形验证码"></div>
            </div>
            <div class="verification" onclick="fnVerif()"></div>
        </div>
        <div class="input">
            <div class="item">
                <div class="name">验证码</div>
                <div class="inp"><input type="tel" id="code" placeholder="请输入验证码"></div>
            </div>
            <div class="code    " onclick="fnSms(this)">获取验证码</div>
        </div>
        <div class="query" onclick="fnSelect()">查询</div>
    </div>
</body>
<script type="text/javascript" src="../framework/template-web.js"></script>
<script type="text/javascript" src="../framework/zepto.min.js"></script>
<script type="text/javascript" src="../script/base.js"></script>
<script type="text/javascript">
    fnVerif();
    //验证码
    function fnVerif(){
       var user_id = fnCookie('USER_ID');
        var imgUrl = SERVER_ADDR+'Shop/verify'+'?user_id='+user_id;
        $( '.verification' ).css( "background" ,"url("+imgUrl+")");
    }

    function fnSms(_el){
        var _param = {};
        if(fnValue("#phone")){
            if( fnVerify( 'Phone' ).test( fnValue( '#phone' ) )){
                _param.phone = fnValue("#phone");
            }else{
                fnToast('手机号码格式错误');
                return
            }
        }else{
            fnToast('请填写手机号码');
            return
        }
        if(fnValue("#verify")){
            fnAjax({
                url: "Shop/check_verify",
                data: {
                    verify:fnValue("#verify"),
                },
            }, function(ret){
                if( !ret.status ){
                    _fn(_el);
                }else{
                    fnToast(ret.msg);
                    return;
                }
            });
        }else{
            fnToast('请填写图形验证码');
            return
        }
        function _fn(_el){
            fnAjax({
                url: "Public/sms",
                data: {
                    phone:fnValue("#phone")
                },
            }, function(ret){
                console.log(ret);
                if( !ret.status ){
                    fnCount(_el, 60);
                    fnToast(ret.msg);
                }else{
                    fnToast(ret.msg);
                }
            });
        }
    }

    function fnSelect(){
        var _param = {};
        if(fnValue("#phone")){
            if( fnVerify( 'Phone' ).test( fnValue( '#phone' ) )){
                _param.phone = fnValue("#phone");
            }else{
                fnToast('手机号码格式错误');
                return
            }
        }else{
            fnToast('请填写手机号码');
            return
        }
        if(fnValue("#code")){
            _param.code = fnValue("#code");
        }else{
            fnToast('请填写手机号码');
            return
        }
        fnAjax({
                url: "Public/checkCode",
                data: _param,
            }, function(ret){
                console.log(ret);
                if( !ret.status ){
                    fnToast(ret.msg,function(){
                        fnOpen("chaxunjieguo.html");
                    });
                }else{
                    fnToast(ret.msg);
                }
            });

    }
    
    // 发送验证码倒计时
    function fnCount(_el, _num){
        if( _num <= 0 ){
            $(_el).removeClass('no-onclick');
            fnValue(_el, '重新发送');
        }else{
            $(_el).addClass('no-onclick');
            fnValue(_el, _num + " 's");
            setTimeout(function(){
                fnCount(_el, --_num);
            }, 1000);
        }
    }

</script>
</html>
